package com.back.campus_back.controller;


import com.back.campus_back.domain.Goods;
import com.back.campus_back.domain.ShoppingCart;
import com.back.campus_back.service.ShoppingCartService;
import com.back.campus_back.service.impl.CollectServiceImpl;
import com.back.campus_back.service.impl.ShoppingCartServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 */
@RestController
@RequestMapping("/shoppingCart")
@Api(tags = "购物车的控制类")
public class ShoppingCartController {
    @Autowired
    ShoppingCartServiceImpl shoppingCartService;

    //根据用户查询对应的购物车信息
    @ApiOperation("根据用户查询对应的购物车信息")
    @GetMapping("/getShoppingCart/{user_id}")
    public List getShoppingCart(@PathVariable(value = "user_id") int user_id){

        return shoppingCartService.getShoppingCart(user_id);
    }

    //  查询购物车的某一条商品信息
    @ApiOperation("查询购物车的某一条商品信息")
    @GetMapping("/getShoppingCartOne/{user_id}/{goods_id}")

    public List<Goods> getShoppingCartOne(@PathVariable(value = "user_id") int user_id,@PathVariable(value = "goods_id") int goods_id){

        return shoppingCartService.getShoppingCartOne(user_id,goods_id);
    }

    //个人添加商品到购物车
    @ApiOperation("个人添加商品到购物车")
    @GetMapping("/addShoppingCart/{user_id}/{goods_id}")
    public Map<String,List> addShoppingCart(@PathVariable(value = "user_id") int user_id, @PathVariable(value = "goods_id") int goods_id){
        return shoppingCartService.addShoppingCart(user_id,goods_id);

    }

    //删除购物车的商品
    @ApiOperation("删除购物车的商品")
    @GetMapping("/deleteShoppingCart/{user_id}/{goods_id}")
    public String deleteShoppingCart(@PathVariable(value = "user_id") int user_id, @PathVariable(value = "goods_id") int goods_id){
        return shoppingCartService.deleteShoppingCart(user_id,goods_id);
    }


}

